using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using GonzalesCore.CoreElements;
using GonzalesCore.CoreManagers;
using Kypris2.CoreElements;
using Kypris2.Utils;
using Jamila2.Tools;

public partial class GonzalesClaimsPendingForFinanceApprovalDetail : System.Web.UI.Page
{
    #region Variables

    protected PrivateLoginSession CurrentPrivateSession = null;
    protected LogManager CurLogManager = null;
    protected GonzalesClaimHeader ResultObj = null;
    protected int TotalColumn = 23;
    protected DataObj CurPageDataObj = new DataObj();
    protected bool IsApprove = true, IsOnHold = false;    

    #region ClaimHavingCreditCard
    protected bool ClaimHavingCreditCard
    {
        get
        {
            return (bool)ViewState["ClaimHavingCreditCard"];
        }

        set
        {
            ViewState["ClaimHavingCreditCard"] = value;
        }
    }

    #endregion

    #region ClaimInternalID
    protected string ClaimInternalID
    {
        get
        {
            return ViewState["ClaimInternalID"].ToString();
        }

        set
        {
            ViewState["ClaimInternalID"] = value;
        }
    }
    #endregion

    #region ResultTable
    protected DataTable ResultTable
    {
        get
        {
            return (DataTable)ViewState["ResultTable"];
        }

        set
        {
            ViewState["ResultTable"] = value;
        }
    }
    #endregion    

    #region ResultTableForRemarks
    protected DataTable ResultTableForRemarks
    {
        get
        {
            return (DataTable)ViewState["ResultTableForRemarks"];
        }

        set
        {
            ViewState["ResultTableForRemarks"] = value;
        }
    }
    #endregion    

    #region FARemarksMessage
    protected string FARemarksMessage
    {
        get
        {
            return ViewState["FARemarksMessage"].ToString();
        }

        set
        {
            ViewState["FARemarksMessage"] = value;
        }
    }
    #endregion

    #endregion

    #region Events

    #region Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        this.SessionCheck();

        this.Table_MessageBox.Visible = false;

        if (!IsPostBack)
        {
            #region Request.QueryString["id"]
            if (Request.QueryString["id"] != null && Request.QueryString["id"].Length == 36)
            {
                this.ClaimInternalID = Request.QueryString["id"];
            }
            else
            {
                Response.Redirect(GonzalesErrorPageRedirect.PageFlowError);
            }
            #endregion

            this.ClaimHavingCreditCard = false;

            this.SwitchLanguage();
            this.PageComponentSetup();

            this.LoadData();    // will load the row together
            this.FillData();

            if (this.ResultTable != null)
            {
                this.GridViewResult.Columns[1].Visible = this.GridViewResult.Columns[2].Visible = (this.ClaimHavingCreditCard);

                DataView ResultView = new DataView(this.ResultTable);
                this.BindData(ResultView);
            }

            // remarks
            this.LoadRemarksData();
            if (this.ResultTableForRemarks != null)
            {
                DataView ResultView = new DataView(this.ResultTableForRemarks);
                ResultView.Sort = "CreatedOn";

                this.GridView_ResultRemarks.DataSource = ResultView;
                this.GridView_ResultRemarks.DataBind();
            }
        }
    }

    #endregion

    #region DropDownList_SortBy_SelectedIndexChanged
    protected void DropDownList_SortBy_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.ResultTable != null)
        {
            DataView ResultView = new DataView(this.ResultTable);
            ResultView.Sort = this.DropDownList_SortBy.SelectedValue;
            this.BindData(ResultView);
        }
    }
    #endregion

    #region Button_Approve_Click

    protected void Button_Approve_Click(object sender, EventArgs e)
    {
        bool smooth = true;
              
        if (smooth)
        {
            using (ClaimManager CurClaimManager = new ClaimManager(this.CurrentPrivateSession))
            {
                int CurrentApproverLevel = 0;
                this.ResultObj = CurClaimManager.GetClaimByInternalID(this.ClaimInternalID);
                /*

                #region Get Approver Level

                using (UserManager CurUserManager = new UserManager(this.CurrentPrivateSession))
                {
                    SystemUsers ApproverList = CurUserManager.GetFinanceApproversByCompany(this.ResultObj.CompanyClaimedFrom.InternalID);

                    if (ApproverList != null)
                    {
                        for (int x = 0; x < ApproverList.Count; x++)
                        {
                            if (ApproverList[x].InternalID.CompareTo(this.CurrentPrivateSession.CurrentLoggedOnUser.InternalID) == 0)
                            {
                                CurrentApproverLevel = ApproverList[x].ApproverLevel;
                            }
                        }
                    }
                    else
                    {
                        smooth = false;
                        string LogID = SwissArmy.UniqueID();
                        this.CurLogManager.LogError(LogID, "[GonzalesClaimsPendingForFinanceApprovalDetail.Button_Approve_Click] : Failed at CurUserManager.GetFinanceApproversByCompany('" + this.ResultObj.CompanyClaimedFrom.InternalID + "') : " + CurUserManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                        this.ShowErrorMessage("Error! " + LogID);
                    }
                }

                #endregion

                bool IsTheEnd = false, HavingNextFinanceApprover = false;
                SystemUser NextFinanceApprover = null;

                using (UserManager CurUserManager = new UserManager(this.CurrentPrivateSession))
                {
                    NextFinanceApprover = CurUserManager.GetFinanceApproverByCompany(
                        CurrentApproverLevel,
                        this.ResultObj.CompanyClaimedFrom.InternalID,
                        ref IsTheEnd,
                        ref HavingNextFinanceApprover);
                }

                if (IsTheEnd)
                {
                    this.ResultObj.Status = GonzalesClaimHeader.TypeOfClaimStatus.SubmittedForPayment;
                    this.ResultObj.FinanceApprovedBy = this.CurrentPrivateSession.CurrentLoggedOnUser;
                    this.ResultObj.FinanceApprovedOn = DateTime.Now;
                }
                else
                {
                    this.ResultObj.Status = GonzalesClaimHeader.TypeOfClaimStatus.FinanceApproval;
                    this.ResultObj.NextFinanceApprover = NextFinanceApprover;
                }
                */

                this.ResultObj.Status = GonzalesClaimHeader.TypeOfClaimStatus.SubmittedForPayment;
                this.ResultObj.FinanceApprovedBy = this.CurrentPrivateSession.CurrentLoggedOnUser;
                this.ResultObj.FinanceApprovedOn = DateTime.Now;
                this.ResultObj.LastUpdatedBy = this.CurrentPrivateSession.CurrentLoggedOnUser;
                this.ResultObj.LastUpdatedOn = DateTime.Now;

                FinanceApproverRemark Remark = null;
                if (this.TextBox_FARemarks.Text.Trim().Length > 0)
                {
                    Remark = new FinanceApproverRemark(SwissArmy.UniqueID());
                    Remark.Content = this.TextBox_FARemarks.Text;
                    Remark.CreatedBy = this.CurrentPrivateSession.CurrentLoggedOnUser;
                    Remark.CreatedDateTime = DateTime.Now;
                    Remark.Level = CurrentApproverLevel;
                    
                    /* No Longer needed
                    if (NextFinanceApprover != null)
                    {
                        Remark.SendTo = NextFinanceApprover;
                    }
                    */
                }

                if (!(smooth = CurClaimManager.UpdateClaimByFinanceApprover(this.ResultObj, Remark)))
                {
                    string LogID = SwissArmy.UniqueID();
                    this.CurLogManager.LogError(LogID, "[GonzalesClaimsPendingForFinanceApprovalDetail.Button_Approve_Click] : Failed at CurUserManager.UpdateClaimByFinanceApprover() : " + CurClaimManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                    this.ShowErrorMessage("Error! " + LogID);
                }
                else
                {
                    // this is to monitor entire claim flow
                    this.CurLogManager.LogAction(this.ClaimInternalID, this.CurrentPrivateSession.CurrentLoggedOnUser.InternalID, GonzalesUserAction.ClaimFinanceApproved, this.ResultObj.Status);

                    //Added By Agnes [16th Aug, 2011]
                    CurLogManager.UpdateLogFVClaimAction(this.ClaimInternalID, this.CurrentPrivateSession.CurrentLoggedOnUser.InternalID, this.CurrentPrivateSession.CurrentLoggedOnUser.DisplayName, ClaimManager.GetClaimStatusInString(this.ResultObj.Status));

                    Response.Redirect("GonzalesClaimsPendingForFinanceApproval.aspx");
                }

            }
        }
    }
    #endregion

    #region Button_Reject_Click

    protected void Button_Reject_Click(object sender, EventArgs e)
    {
        bool smooth = true;

        if (this.TextBox_FARemarks.Text.Trim().Length == 0)
        {
            this.ShowErrorMessage(this.FARemarksMessage);
            smooth = false;
        }
        else
        {
            using (ClaimManager CurClaimManager = new ClaimManager(this.CurrentPrivateSession))
            {
                this.ResultObj = CurClaimManager.GetClaimByInternalID(this.ClaimInternalID);

                //this.ResultObj.Status = GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinanceApprover;
                this.ResultObj.LastUpdatedBy = this.CurrentPrivateSession.CurrentLoggedOnUser;
                this.ResultObj.LastUpdatedOn = DateTime.Now;

                SystemUser PreviousPersonnel = null;
                PreviousPersonnel = new SystemUser(this.ResultObj.ProcessedBy.InternalID, this.ResultObj.ProcessedBy.DisplayName);
                this.ResultObj.Status = GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinanceApproverToFA;

                /*
                int CurrentApproverLevel = 0;

                using (UserManager CurUserManager = new UserManager(this.CurrentPrivateSession))
                {
                    
                    SystemUsers ApproverList = CurUserManager.GetFinanceApproversByCompany(this.ResultObj.CompanyClaimedFrom.InternalID);

                    if (ApproverList != null)
                    {
                        int TargetIndex = 0;

                        for (int x = 0; x < ApproverList.Count; x++)
                        {
                            if (ApproverList[x].InternalID.CompareTo(this.CurrentPrivateSession.CurrentLoggedOnUser.InternalID) == 0)
                            {
                                TargetIndex = x - 1;
                                CurrentApproverLevel = ApproverList[x].ApproverLevel;

                                if (TargetIndex >= 0)
                                {
                                    PreviousPersonnel = ApproverList[TargetIndex];
                                    this.ResultObj.NextFinanceApprover = PreviousPersonnel;
                                }
                                else
                                {
                                    // back to finance admin
                                    PreviousPersonnel = new SystemUser(this.ResultObj.ProcessedBy.InternalID, this.ResultObj.ProcessedBy.DisplayName);
                                    this.ResultObj.Status = GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinanceApproverToFA;
                                }
                            }
                        }
                    }
                    else
                    {
                        string LogID = SwissArmy.UniqueID();
                        this.CurLogManager.LogError(LogID, "[GonzalesClaimsPendingForFinanceApprovalDetail.Button_Reject_Click] : Failed at CurUserManager.GetFinanceApproversByCompany('" + this.ResultObj.CompanyClaimedFrom.InternalID + "') : " + CurClaimManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                        this.ShowErrorMessage("Error! " + LogID);
                    }
                    
                }
                */

                FinanceApproverRemark Remark = null;

                if (PreviousPersonnel != null)
                {
                    if (this.TextBox_FARemarks.Text.Trim().Length > 0)
                    {
                        Remark = new FinanceApproverRemark(SwissArmy.UniqueID());
                        Remark.Content = this.TextBox_FARemarks.Text;
                        Remark.CreatedBy = this.CurrentPrivateSession.CurrentLoggedOnUser;
                        Remark.CreatedDateTime = DateTime.Now;
                        //Remark.Level = CurrentApproverLevel;
                        Remark.SendTo = PreviousPersonnel;
                    }
                }

                if (!(smooth = CurClaimManager.UpdateClaimByFinanceApprover(this.ResultObj, Remark)))
                {
                    string LogID = SwissArmy.UniqueID();
                    this.CurLogManager.LogError(LogID, "[GonzalesClaimsPendingForFinanceApprovalDetail.Button_Reject_Click] : Failed at CurUserManager.UpdateClaimByFinanceApprover() : " + CurClaimManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                    this.ShowErrorMessage("Error! " + LogID);

                }
                else
                {
                    // this is to monitor entire claim flow
                    this.CurLogManager.LogAction(this.ClaimInternalID, this.CurrentPrivateSession.CurrentLoggedOnUser.InternalID, GonzalesUserAction.ClaimRejectedByFinanceAapprover, this.ResultObj.Status);

                    //Added By Agnes [16th Aug, 2011]
                    CurLogManager.UpdateLogFVClaimAction(this.ClaimInternalID, this.CurrentPrivateSession.CurrentLoggedOnUser.InternalID, this.CurrentPrivateSession.CurrentLoggedOnUser.DisplayName, ClaimManager.GetClaimStatusInString(this.ResultObj.Status));

                    Response.Redirect("GonzalesClaimsPendingForFinanceApproval.aspx");
                }
            }
        }
    }

    #endregion

    #region ImageButton_Cancel_Click
    protected void ImageButton_Cancel_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("GonzalesClaimsPendingForFinanceApproval.aspx");
    }

    #endregion


    #endregion

    #region Customized Methods

    #region SessionCheck
    public void SessionCheck()
    {

        if (Session[GonzalesCommonNamingConvention.CurrentPrivateSession] != null)
        {
            this.CurrentPrivateSession = (PrivateLoginSession)Session[GonzalesCommonNamingConvention.CurrentPrivateSession];
            this.CurLogManager = new LogManager(this.CurrentPrivateSession);    // activate Log Manager
        }
        else
        {
            Response.Redirect(GonzalesErrorPageRedirect.SessionError);
        }

    }
    #endregion

    #region PageComponentSetup
    protected void PageComponentSetup()
    {
        //this.Label_TotalAmount.Text += " (" + this.CurrentPrivateSession.CurrentLoggedOnUser.DefaultCurrency.InternalID + ")";
        this.Label_TotalLocalAmount.Text = " 0";                       
        this.TextBox_Owning.Style.Add(HtmlTextWriterStyle.TextAlign, "right");
        this.TextBox_TotalAmountAlreadyPaid.Style.Add(HtmlTextWriterStyle.TextAlign, "right");
        this.TextBox_TotalPersonalExpenses.Style.Add(HtmlTextWriterStyle.TextAlign, "right");


        // cheque info
        this.Table_ChequeInfo.Visible = false;

        // file upload
        this.Button_FileManager.Attributes["onclick"] = "ShowModal('FileManager', '', 'id=" + this.ClaimInternalID + "&NoEdit=1'); return false;";
        this.Button_PrinterFriendly.Attributes["onclick"] = "var windetail = window.open('GonzalesViewClaim.aspx?id=" + this.ClaimInternalID + "','','scrollbars=yes,width=800,height=600'); return false;";
        this.Button_PrinterFriendlyNameList.Attributes["onclick"] = "var windetail = window.open('GonzalesViewClaimNameList.aspx?id=" + this.ClaimInternalID + "','','scrollbars=yes,width=800,height=600'); return false;";
    }
    #endregion

    #region SwitchLanguage
    protected void SwitchLanguage()
    {
        try
        {
            using (MultiLingualFactory CurLanguageFactory = MultiLingualEngine.GetMultiLingualFactory(this, this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage.InternalID))
            {
                this.Label_Category.Text = CurLanguageFactory.DisplayValue("Category");
                this.Label_ChequeNo.Text = CurLanguageFactory.DisplayValue("ChequeNo");
                this.Label_ClaimNum.Text = CurLanguageFactory.DisplayValue("ClaimNum");
                this.Label_ClaimPeriod.Text = CurLanguageFactory.DisplayValue("ClaimPeriod");
                this.Label_EmployeeName.Text = CurLanguageFactory.DisplayValue("EmployeeName");
                this.Label_EmployeeNo.Text = CurLanguageFactory.DisplayValue("EmployeeNo");
                this.Label_FinanceApproverRemarks.Text = CurLanguageFactory.DisplayValue("FinanceApproverRemarks");
                this.Label_Information.Text = CurLanguageFactory.DisplayValue("Information");
                this.Label_IssuedBank.Text = CurLanguageFactory.DisplayValue("IssuedBank");
                this.Label_OwningEmployee.Text = CurLanguageFactory.DisplayValue("OwningEmployee");
                this.Label_PageTitle.Text = CurLanguageFactory.DisplayValue("PageTitle");
                this.Label_ProfitCenter.Text = CurLanguageFactory.DisplayValue("ProfitCenter");
                this.Label_Purpose.Text = CurLanguageFactory.DisplayValue("Purpose");
                this.Label_Remarks.Text = CurLanguageFactory.DisplayValue("Remarks");
                this.Label_SubmissionDate.Text = CurLanguageFactory.DisplayValue("SubmissionDate");
                this.Label_TotalAmount.Text = CurLanguageFactory.DisplayValue("TotalAmount");
                this.Label_TotalAmountLessPaid.Text = CurLanguageFactory.DisplayValue("TotalAmountLessPaid");

                this.Button_FileManager.Text = CurLanguageFactory.DisplayValue("FileManager");
                this.Button_PrinterFriendly.Text = CurLanguageFactory.DisplayValue("PrinterFriendly");
                this.Button_PrinterFriendlyNameList.Text = CurLanguageFactory.DisplayValue("PrinterFriendlyNameList");
                this.Button_Approve.Attributes["onclick"] = "return confirm('" + CurLanguageFactory.DisplayValue("ApprovedMessage") + "');";
                this.Button_Reject.Attributes["onclick"] = "return confirm('" + CurLanguageFactory.DisplayValue("RejectedMessage") + "');";
                //this.button_onhol.Attributes["onclick"] = "return confirm('Are you sure you want to reject this claim?');";

                this.FARemarksMessage = CurLanguageFactory.DisplayValue("FARemarksMessage");

                // sort order
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("OriginalOrder"), this.CurPageDataObj.Order));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ExpenseDetail"), this.CurPageDataObj.ExpenseDetail));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ClaimDateInStr"), this.CurPageDataObj.ClaimDate));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("Country"), this.CurPageDataObj.Country));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("AmountOutInStr"), this.CurPageDataObj.ClaimedAmount));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ExchangeCurrency"), this.CurPageDataObj.ClaimedAmountCurrency));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ProjectID"), this.CurPageDataObj.ProjectID));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ChargeToProfitCenter"), this.CurPageDataObj.ChargeToProfitCenter));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ChargeToEmployeeID"), this.CurPageDataObj.ChargeToEmployeeiD));

                this.GridViewResult.Columns[0].HeaderText = CurLanguageFactory.DisplayValue("ExpenseDetail");
                this.GridViewResult.Columns[2].HeaderText = "";
                this.GridViewResult.Columns[3].HeaderText = CurLanguageFactory.DisplayValue("Country");
                this.GridViewResult.Columns[4].HeaderText = CurLanguageFactory.DisplayValue("City");
                this.GridViewResult.Columns[5].HeaderText = CurLanguageFactory.DisplayValue("ClaimDateInStr");
                this.GridViewResult.Columns[6].HeaderText = CurLanguageFactory.DisplayValue("Description");
                this.GridViewResult.Columns[7].HeaderText = CurLanguageFactory.DisplayValue("ClaimantRemarks");
                this.GridViewResult.Columns[9].HeaderText = CurLanguageFactory.DisplayValue("ExchangeCurrency");
                this.GridViewResult.Columns[10].HeaderText = CurLanguageFactory.DisplayValue("ExchangeRate");
                this.GridViewResult.Columns[11].HeaderText = CurLanguageFactory.DisplayValue("AmountOutInStr");
                this.GridViewResult.Columns[12].HeaderText = CurLanguageFactory.DisplayValue("AmountFinalInStr");
                this.GridViewResult.Columns[13].HeaderText = CurLanguageFactory.DisplayValue("FinanceRemarks");
                this.GridViewResult.Columns[14].HeaderText = CurLanguageFactory.DisplayValue("ProjectID");
                this.GridViewResult.Columns[15].HeaderText = CurLanguageFactory.DisplayValue("ChargeToProfitCenter");
                this.GridViewResult.Columns[16].HeaderText = CurLanguageFactory.DisplayValue("ChargeToEmployeeID");

                this.GridView_ResultRemarks.Columns[0].HeaderText = CurLanguageFactory.DisplayValue("CreatedOnInStr");
                this.GridView_ResultRemarks.Columns[1].HeaderText = CurLanguageFactory.DisplayValue("Content");
                this.GridView_ResultRemarks.Columns[2].HeaderText = CurLanguageFactory.DisplayValue("CreatedByName");

            }
        }
        catch (Exception ex)
        {
            this.CurLogManager.LogError("[GonzalesClaimsPendingForVerificationDetail.SwitchLanguage.EX] : " + ex.Message, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
        }

    }
    #endregion
       
    #region TableGridComponengtSetup
    protected void TableGridComponengtSetup()
    {

        

    }
    #endregion

    #region ShowErrorMessage
    protected void ShowErrorMessage(string ErrorMessage)
    {
        this.Table_MessageBox.Visible = true;
        this.Table_MessageBox.Rows[0].Cells[0].Text = ErrorMessage;
    }
    #endregion

    #endregion

    #region Data Operation

    #region LoadData

    protected void LoadData()
    {
        decimal TotalPersonalExpenses = 0;

        using (ClaimManager CurClaimManager = new ClaimManager(this.CurrentPrivateSession))
        {
            this.ResultObj = CurClaimManager.GetClaimByInternalID(this.ClaimInternalID);

            //Added By Agnes[09 April 2009] - For Enhancement to enabled/disabled the PrinterFriendlyNameList
            //if (this.ResultObj.Category == CategoryOfClaim.Entertainment)
            //    this.Button_PrinterFriendlyNameList.Visible = true;

            if (this.ResultObj != null)
            {
                this.ResultObj.ClaimDetails = CurClaimManager.GetClaimItemsByClaimHeaderInLang(this.ClaimInternalID, this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage);

                if (this.ResultObj.ClaimDetails != null)
                {
                    this.ResultTable = new DataTable();

                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.Order, Type.GetType("System.Int32")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.ExpenseDetail, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.Description, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.Remarks, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.ClaimDate, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.ClaimDateInStr, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.ClaimDetailType, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.IsPersonnal, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.Country, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.City, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.ClaimedAmount, Type.GetType("System.Decimal")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.ClaimedAmountInStr, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.ExchangeCurrency, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.ExchangeRate, Type.GetType("System.Decimal")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.AmountOut, Type.GetType("System.Decimal")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.AmountOutInStr, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.AmountFinal, Type.GetType("System.Decimal")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.AmountFinalInStr, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.FinanceRemarks, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.ProjectID, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.ChargeToProfitCenter, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.ChargeToEmployeeiD, Type.GetType("System.String")));

                    //Added By Agnes[26 March 2009] - requested by Tyco Taiwan
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.ShowDetail, Type.GetType("System.String")));

                    for (int x = 0; x < this.ResultObj.ClaimDetails.Count; x++)
                    {
                        GonzalesClaimItem CurClaimItem = (GonzalesClaimItem) ResultObj.ClaimDetails[x];
                        DataRow ResultRow = this.ResultTable.NewRow();

                        this.ClaimHavingCreditCard = (CurClaimItem.ClaimDetailType == TypeOfClaimDetail.CreditCard) ? true : this.ClaimHavingCreditCard;

                        ResultRow[this.CurPageDataObj.Order] = CurClaimItem.Order;
                        ResultRow[this.CurPageDataObj.ExpenseDetail] = CurClaimItem.ClaimType.DisplayName;
                        ResultRow[this.CurPageDataObj.Description] = CurClaimItem.Description;
                        ResultRow[this.CurPageDataObj.Remarks] = CurClaimItem.Remarks;
                        ResultRow[this.CurPageDataObj.ClaimDate] = CurClaimItem.ClaimDate;
                        ResultRow[this.CurPageDataObj.ClaimDateInStr] = SwissArmy.DateConvert(CurClaimItem.ClaimDate, this.CurrentPrivateSession.DateFormatInUse, "/");
                        ResultRow[this.CurPageDataObj.ClaimedAmount] = CurClaimItem.ClaimedAmount;
                        ResultRow[this.CurPageDataObj.ClaimedAmountInStr] = CurClaimItem.ClaimedAmount.ToString(GonzalesGeneralVariables.CurrencyFormat);
                        ResultRow[this.CurPageDataObj.ClaimDetailType] = (CurClaimItem.ClaimDetailType == TypeOfClaimDetail.CreditCard) ? "<img src='" + GonzalesImages.Icon_CreditCard + "'>" : "";
                        ResultRow[this.CurPageDataObj.IsPersonnal] = (CurClaimItem.IsPersonnal) ? "<img src='" + GonzalesImages.Icon_Personal + "'>" : "";
                        ResultRow[this.CurPageDataObj.Country] = CurClaimItem.Country.DisplayName;
                        ResultRow[this.CurPageDataObj.City] = CurClaimItem.City;
                        ResultRow[this.CurPageDataObj.ExchangeCurrency] = CurClaimItem.ExchangeCurrency.DisplayName;
                        ResultRow[this.CurPageDataObj.ExchangeRate] = CurClaimItem.ExchangeRate;
                        ResultRow[this.CurPageDataObj.AmountOut] = CurClaimItem.AmountOut;
                        ResultRow[this.CurPageDataObj.AmountOutInStr] = CurClaimItem.AmountOut.ToString(GonzalesGeneralVariables.CurrencyFormat);
                        ResultRow[this.CurPageDataObj.AmountFinal] = CurClaimItem.AmountFinal;
                        ResultRow[this.CurPageDataObj.AmountFinalInStr] = CurClaimItem.AmountFinal.ToString(GonzalesGeneralVariables.CurrencyFormat);
                        ResultRow[this.CurPageDataObj.FinanceRemarks] = CurClaimItem.FinanceRemarks;
                        ResultRow[this.CurPageDataObj.ProjectID] = CurClaimItem.ProjectID;
                        ResultRow[this.CurPageDataObj.ChargeToProfitCenter] = CurClaimItem.ChargeToProfitCenter;
                        ResultRow[this.CurPageDataObj.ChargeToEmployeeiD] = CurClaimItem.ChargeToEmployeeiD;

                        //Added By Agnes[26 March 2009] - requested by Tyco Taiwan
                        ResultRow[this.CurPageDataObj.ShowDetail] = (CurClaimItem.Remarks.IndexOf("[ENT]") >= 0) ? "<a href='#' onclick=\"ShowSpecialPopOut('" + CurClaimItem.ClaimType.GLCode + "', null, 'NoEdit=1&id=" + this.ClaimInternalID + "&did=" + CurClaimItem.InternalID + "&remarks=" + CurClaimItem.Remarks.Replace("'", "#") + "');\"><img border='0' src='" + GonzalesImages.Icon_Detail + "'></a>" : "";

                        if (CurClaimItem.ClaimDetailType == TypeOfClaimDetail.CreditCard && CurClaimItem.IsPersonnal)
                            TotalPersonalExpenses -= CurClaimItem.AmountOut;

                        ResultTable.Rows.Add(ResultRow);
                    }
                    this.TextBox_TotalPersonalExpenses.Text = TotalPersonalExpenses.ToString(GonzalesGeneralVariables.CurrencyFormat);
                } 
                else
                {
                    string LogID = SwissArmy.UniqueID();
                    this.CurLogManager.LogError(LogID, "[GonzalesClaimsPendingForFinanceApprovalDetail.LoadData] : Failed at CurClaimManager.GetClaimItemsByClaimHeaderInLang() : " + CurClaimManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                    this.ShowErrorMessage("Error! " + LogID);
                }
            }
            else
            {
                string LogID = SwissArmy.UniqueID();
                this.CurLogManager.LogError(LogID, "[GonzalesClaimsPendingForFinanceApprovalDetail.LoadData] : Failed at CurClaimManager.GetClaimByInternalID('" + this.ClaimInternalID + "') : " + CurClaimManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                this.ShowErrorMessage("Error! " + LogID);

            }

        }
    }

    #endregion

    #region LoadRemarksData

    protected void LoadRemarksData()
    {

            using (ClaimManager CurClaimManager = new ClaimManager(this.CurrentPrivateSession))
            {
                FinanceApproverRemarks ResultRemarks = CurClaimManager.GetFinanceApproverRemarks(
                    this.CurrentPrivateSession.CurrentLoggedOnUser.InternalID,
                    this.ClaimInternalID);

                if (ResultRemarks != null)
                {
                    this.ResultTableForRemarks = new DataTable();
                    ResultTableForRemarks.Columns.Add(new DataColumn("InternalID", Type.GetType("System.String")));
                    ResultTableForRemarks.Columns.Add(new DataColumn("Content", Type.GetType("System.String")));
                    ResultTableForRemarks.Columns.Add(new DataColumn("CreatedOn", Type.GetType("System.DateTime")));
                    ResultTableForRemarks.Columns.Add(new DataColumn("CreatedOnInStr", Type.GetType("System.String")));
                    ResultTableForRemarks.Columns.Add(new DataColumn("CreatedByName", Type.GetType("System.String")));

                    foreach (FinanceApproverRemark Remark in ResultRemarks)
                    {
                        DataRow ResultRow = this.ResultTableForRemarks.NewRow();

                        ResultRow["InternalID"] = Remark.InternalID;
                        ResultRow["Content"] = Remark.Content;
                        ResultRow["CreatedOn"] = Remark.CreatedDateTime;
                        ResultRow["CreatedOnInStr"] = SwissArmy.DateConvert(Remark.CreatedDateTime, this.CurrentPrivateSession.DateFormatInUse, "/", true);
                        ResultRow["CreatedByName"] = Remark.CreatedBy.DisplayName;

                        this.ResultTableForRemarks.Rows.Add(ResultRow);

                    }
                }
                else
                {
                    string LogID = SwissArmy.UniqueID();
                    this.CurLogManager.LogError(LogID, "[GonzalesClaimsPendingForFinanceApprovalDetail.LoadRemarksData] : Failed at CurClaimManager.GetFinanceApproverRemarks() : " + CurClaimManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                    this.ShowErrorMessage("Error! " + LogID);

                }
            }

    }

    #endregion

    #region BindData
    private void BindData(DataView result)
    {
        this.GridViewResult.DataSource = result;
        this.GridViewResult.DataBind();
    }

    private void BindData(DataView result, int pageindex)
    {
        this.GridViewResult.PageIndex = pageindex;
        this.GridViewResult.DataSource = result;
        this.GridViewResult.DataBind();
    }
    #endregion

    #region FillData

    protected void FillData()
    {
        // fill in the blank
        this.LabelValue_EmployeeName.Text = this.ResultObj.ClaimedBy.DisplayName + "(" + this.ResultObj.ClaimedBy.EmailID + ")";
        this.LabelValue_EmployeeNo.Text = this.ResultObj.ClaimedBy.EmployeeID;
        this.LabelValue_ClaimNo.Text = ResultObj.ClaimID;
        this.LabelValue_Purpose.Text = ResultObj.Reasons;
        this.LabelValue_ProfitCenter.Text = this.CurrentPrivateSession.CurrentLoggedOnUser.CostCenter;
        this.LabelValue_SubmissionDate.Text = SwissArmy.DateConvert(this.ResultObj.SubmittedOn, this.CurrentPrivateSession.DateFormatInUse, "/");
        this.LabelValue_Category.Text = ClaimManager.GetClaimCategoryInString(this.ResultObj.Category);
        if (this.ResultObj.ProjectedOn != DateTime.MinValue)
            this.LabelValue_ClaimPeriod.Text = this.ResultObj.ProjectedOn.ToString("MMMM") + " " + this.ResultObj.ProjectedOn.Year.ToString();

        //this.LabelValue_ProjectedPaymentDate.Text = SwissArmy.DateConvert(this.ResultObj.ProjectedOn, this.CurrentPrivateSession.DateFormatInUse, "/");

        this.Label_TotalAmount.Text += " (" + this.ResultObj.LocalCurrency.InternalID + ")";
        this.Label_TotalLocalAmount.Text = (this.ResultObj.TotalClaimedAmount - decimal.Parse(this.TextBox_TotalPersonalExpenses.Text)).ToString(GonzalesGeneralVariables.CurrencyFormat);
        this.TextBox_Owning.Text = this.ResultObj.TotalLocalActualAmountLeft.ToString(GonzalesGeneralVariables.CurrencyFormat);
        this.TextBox_TotalAmountAlreadyPaid.Text = this.ResultObj.TotalLocalAmountAlreadyPaid.ToString(GonzalesGeneralVariables.CurrencyFormat);

        if (this.ResultObj.ChequeNo.Length > 0)
        {
            this.Table_ChequeInfo.Visible = true;
            this.LabelValue_ChequeNo.Text = this.ResultObj.ChequeNo;
            this.LabelValue_IssuedBank.Text = this.ResultObj.ChequeIssuesBank;
        }

    }

    #endregion

    #endregion
   
    #region Class: DataObj

    public class DataObj
    {
        public readonly string InternalID = "InternalID";
        public readonly string ParentID = "ParentID";
        public readonly string ParentIDInFI = "ParentIDInFI";
        public readonly string IsNew = "IsNew";
        public readonly string Order = "Order";
        public readonly string ClaimDetailType = "DetailType";
        public readonly string ClaimType = "ClaimType";
        public readonly string ClaimDate = "ClaimDate";
        public readonly string ClaimDateInStr = "ClaimDateInStr";
        public readonly string Description = "Description";
        public readonly string Remarks = "Remarks";
        public readonly string ExpenseDetail = "ExpenseDetail";
        public readonly string Country = "Country";
        public readonly string City = "City";
        public readonly string ClaimedAmountCurrency = "ClaimedAmountCurrency";
        public readonly string ClaimedAmount = "ClaimedAmount";
        public readonly string ClaimedAmountInStr = "ClaimedAmountInStr";
        public readonly string ExchangeCurrency = "ExchangeCurrency";
        public readonly string ExchangeRate = "ExchangeRate";
        public readonly string Tax = "Tax";
        public readonly string AmountOutCurrency = "AmountOutCurrency";
        public readonly string AmountOut = "AmountOut";
        public readonly string AmountOutInStr = "AmountOutInStr";
        public readonly string AmountFinal = "AmountFinal";
        public readonly string AmountFinalInStr = "AmountFinalInStr";
        public readonly string FinanceRemarks = "FinanceRemarks";
        public readonly string FinanceSate = "FinanceState";
        public readonly string HavingReceipts = "HavingReceipts";
        public readonly string HavingPopOut = "HavingPopOut";
        public readonly string IsPersonnal = "IsPersonal";
        public readonly string ProjectID = "ProjectID";
        public readonly string ChargeToProfitCenter = "ChargeToProfitCenter";
        public readonly string ChargeToEmployeeiD = "ChargeToEmployeeiD";

        //Added By Agnes[26 March 2009] - requested by Tyco Taiwan
        public readonly string ShowDetail = "ShowDetail";
    }

    #endregion
}
